#coding=utf-8

from django.db import models

from django.utils.translation import get_language_from_request, ugettext_lazy as _
from django.contrib.auth.models import User

Permission = (
    (1,_('Find questioner')),
    (2,_('Find answerer')),
    (4,_('Show answer detail')),
    (8,_('Show answer stastics')),
)

RoleType = (
    ('Q', _('Questioner')),
    ('A', _('Answerer')),
    ('T', _('Target')),
)

class Coin(models.Model):
    user = models.ForeignKey(User, unique=True, verbose_name=_("user"))
    coin = models.IntegerField(default=0, verbose_name=_("coin"))
    
#class QCatagory(models.Model):
#    cataname = models.CharField(max_length=128, verbose_name=_("catagory"))
    
#class QTemplate(models.Model):
#    catagory = models.ForeignKey(QCatagory, verbose_name=_("catagory"))
#    question = models.TextField(verbose_name=_("question"))
    
class Question(models.Model):
    #catagory = models.ForeignKey(QCatagory, verbose_name=_("catagory"))
    question = models.TextField(verbose_name=_("question"))
    
    def __unicode__(self):
        return self.question    
    
class ACL(models.Model):
    user = models.ForeignKey(User, verbose_name=_("user"))
    question = models.ForeignKey(Question, verbose_name=_("question"))
    permission = models.IntegerField(max_length=32, choices=Permission, verbose_name=_("permission"))
    
    def __unicode__(self):
        return u'%s, %s, %s'%(self.user, self.question, self.permission)     
    
class QRole(models.Model):
    question = models.ForeignKey(Question, verbose_name=_("question"))
    user = models.ForeignKey(User, verbose_name=_("user"))
    role = models.CharField(max_length=32, choices=RoleType, verbose_name=_("role"))
    
    def __unicode__(self):
        return u'%s, %s, %s'%(self.user, self.question, self.role)
    
class Answer(models.Model):
    user = models.ForeignKey(User, verbose_name=_("user"))
    question = models.ForeignKey(Question, verbose_name=_("question"))
    answer = models.TextField(verbose_name=_("question"))
   
    def __unicode__(self):
        return u'%s, %s, %s'%(self.user, self.question, self.answer)

########################################################
##
##          testcases for model
##
########################################################
from django.utils import unittest

class AnimalTestCase(unittest.TestCase):
    def setUp(self):
        Pass

    def testSpeaking(self):
        Pass